# Maintainer (ArchLinux): Andrea Scarpino <andrea@archlinux.org>
# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_realname=extra-cmake-modules
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.101.0
pkgrel=1
pkgdesc='Extra CMake modules (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://invent.kde.org/frameworks/extra-cmake-modules'
license=('LGPL')
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
depends=("${MINGW_PACKAGE_PREFIX}-cmake")
makedepends=("${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-requests")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"{,.sig}
        "set-AUTOSTATICPLUGINS.patch"
        "tar-force-local.patch")
sha256sums=('8c4c561310db587d390a6c84afc97e1addbaddd73b9d7a4c7309c5da9b9bc8f2'
            'SKIP'
            '8b0a5b5d72802f095086cf2adb30d37dc1033e877c8b7d709b251ec6bf3535ab'
            '5455ec650f830a58309e43fac597beb26faa9076b62742c4454746f94744ccb8')
validpgpkeys=('53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB') # David Faure <faure@kde.org>

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Make sure to update patch in git style because CMake
  # installs *.orig files if hunks are in different offset
  patch -Np1 -i "${srcdir}/set-AUTOSTATICPLUGINS.patch"
  patch -Np1 -i "${srcdir}/tar-force-local.patch"
  find . -name "*.orig" -exec rm -f {} \;
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_HTML_DOCS=OFF \
    -DBUILD_QTHELP_DOCS=OFF \
    -DBUILD_TESTING=OFF \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .
}
